package com.gzhryc.shared_device.pcl.code.dao.db;

import com.gzhryc.common.StringTools;
import com.gzhryc.common.json.JsonTools;
import com.gzhryc.jdbc.annotaion.Column;
import com.gzhryc.jdbc.annotaion.Id;
import com.gzhryc.jdbc.annotaion.JoinField;
import com.gzhryc.jdbc.annotaion.Table;
import com.gzhryc.shared_device.pcl.code.dao.enums.PCLFeeTemplateEnum;
import com.gzhryc.shared_device.pcl.code.dao.models.SetMealContent;

import java.io.Serializable;
import java.util.Date;

@Table(name="pcl_free_template")
public class PCLFeeTemplate implements Serializable {

    private static final long serialVersionUID = 1L;

	@Id(autoIncrement = 1000)
    @Column(notNull = true, note = "模版ID")
    protected Long id;

    @Column(name = "user_id", notNull = true, note = "用户ID")
    protected Long userId;

    @Column(notNull = true,length = 64, note = "模版标题")
    protected String title;

    @Column(name = "device_type_id",notNull = true,note = "设备类型ID")
    protected String deviceTypeId;

    @Column(name = "set_meal_content", type = "TEXT", notNull = true, note = "套餐内容")
    protected String setMealContent;

    @Column(notNull = true,defVal = "1",note = "模版状态")
    protected Integer state;

    @Column(name = "update_date", autoUpdateTime = true, note = "最后修改时间")
    protected Date updateDate;

    @Column(name = "create_date")
    protected Date createDate;

    @JoinField(name = "name", fromField = "user_id", toTable = "user_info",type = "LEFT")
    protected String userName;

    @JoinField(name = "name", fromField = "device_type_id", toTable = "device_type")
    protected String deviceTypeName;

    protected Boolean currentUse;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDeviceTypeId() {
        return deviceTypeId;
    }

    public void setDeviceTypeId(String deviceTypeId) {
        this.deviceTypeId = deviceTypeId;
    }

    public String getSetMealContent() {
        return setMealContent;
    }

    public void setSetMealContent(String setMealContent) {
        this.setMealContent = setMealContent;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDeviceTypeName() {
        return deviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        this.deviceTypeName = deviceTypeName;
    }

    public String getStateName(){
        return PCLFeeTemplateEnum.State.note(this.state);
    }

    public String getFeeInfo(){
        if(StringTools.isNotBlank(setMealContent)) {
            SetMealContent content = JsonTools.fromJson(setMealContent, SetMealContent.class);
            if(content != null && content.getItems().size() > 0) {
                String feeInfo = "";
                for(SetMealContent.Item item : content.getItems()) {
                    feeInfo = feeInfo + "," + item.getTimes() + "分钟" + item.getMoneyStr()+"元";
                }
                feeInfo = feeInfo.substring(1);
                return feeInfo;
            }
        }
        return null;
    }

    public Boolean getCurrentUse() {
        return currentUse;
    }

    public void setCurrentUse(Boolean currentUse) {
        this.currentUse = currentUse;
    }
}
